import { BasicColumn, FormSchema } from '/@/components/Table';
import { getPeriodTree } from '/@/api/common/api';
import { render } from '/@/utils/common/renderUtils';
import dayjs from 'dayjs';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();

// export const currentMoth = () => {
//   const year = new Date().getFullYear();
//   let month = new Date().getMonth() + 1;
//   if (10 > month) {
//     // @ts-ignore
//     month = '0' + month;
//   }
//   return year + month;
// };

export const searchFormSchema: FormSchema[] = [
  {
    field: 'periodCode',
    label: '考核周期',
    component: 'ApiTreeSelect',
    componentProps: {
      api: getPeriodTree,
      fieldNames: {
        children: 'child',
        label: 'periodName',
        value: 'periodCode',
      },
    },
    colProps: { span: 6 },
    defaultValue: dayjs().format('YYYYMM'),
  },
  {
    field: 'orgCode',
    component: 'Select',
    label: '班组1',
    componentProps: {
      options: userStore.getTeamList,
    },
    defaultValue: userStore.getOrgCode,
    colProps: { span: 6, },
  },
  {
    field: 'psnName',
    label: '员工姓名',
    component: 'Input',
    colProps: { span: 6 },
  },
];

// @ts-ignore
export const columns: BasicColumn = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 80,
    ifShow: false,
  },
  {
    title: '考核周期',
    dataIndex: 'periodCode',
    width: 120,
    align: 'center',
    fixed: 'left',
  },
  {
    title: '上级部门',
    dataIndex: 'parentOrgName',
    width: 140,
    align: 'center',
  },
  {
    title: '班组名称',
    dataIndex: 'orgName',
    width: 140,
    align: 'center',
  },
  {
    title: '员工姓名',
    dataIndex: 'psnName',
    width: 90,
    align: 'center',
  },
  {
    title: '员工工号',
    dataIndex: 'psnNum',
    width: 90,
    align: 'center',
    ifShow: false,
  },
  {
    title: '绩效等级',
    dataIndex: 'level',
    width: 140,
    align: 'center',
    editComponent: 'Select',
  },
  {
    title: '月度考核得分',
    dataIndex: 'finalScore',
    width: 140,
    align: 'center',
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    align: 'center',
    customRender: ({ text }) => {
      return render.renderDict(text, 'epm_team_resultType');
    },
  },
];
